﻿Imports System.Data.OleDb
Imports System.Data
Partial Class Jobs
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            'If Request.Params("ID") = "" Then Response.Redirect("Jobs.aspx")
            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("SingleMomMemberConnectionString").ConnectionString)
            Dim SqlString As String = "SELECT * FROM Jobs"
            Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
            cmd.CommandType = CommandType.Text
            oleDbConn.Open()
            Dim dataReader = cmd.ExecuteReader()
            GridView1.DataSource = dataReader
            GridView1.DataBind()


        End If
    End Sub


    Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        'If IsPostBack = False Then
        Dim myGUID = Guid.NewGuid()
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("SingleMomMemberConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into Jobs(JobTitle,Description,Qualifications,StartDate,Location,Employer,Details,Contact,PostedBy) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_JobTitle.Text)
        cmd.Parameters.AddWithValue("@f2", tb_Description.Text)
        cmd.Parameters.AddWithValue("@f3", tb_Qualifications.Text)
        cmd.Parameters.AddWithValue("@f4", tb_StartDate.Text)
        cmd.Parameters.AddWithValue("@f5", tb_Location.Text)
        cmd.Parameters.AddWithValue("@f6", tb_Employer.Text)
        cmd.Parameters.AddWithValue("@f7", tb_Details.Text)
        cmd.Parameters.AddWithValue("@f8", tb_Contact.Text)
        cmd.Parameters.AddWithValue("@f9", User.Identity.Name)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()

        ''''''Now, fill the gridview on the page

        Dim fillComments As String = "SELECT * FROM Jobs"
        Dim fillCommentsCmd As OleDbCommand = New OleDbCommand(fillComments, oleDbConn)
        Dim dataReader = fillCommentsCmd.ExecuteReader()
        GridView1.DataSource = dataReader
        GridView1.DataBind()


        'End If
        'free the textboxes of texts
        tb_JobTitle.Text = ""
        tb_Description.Text = ""
        tb_Qualifications.Text = ""
        tb_StartDate.Text = ""
        tb_Location.Text = ""
        tb_Employer.Text = ""
        tb_Details.Text = ""
        tb_Contact.Text = ""


    End Sub


End Class
